package com.lottery.im.module.service.presenter;

import android.app.Activity;
import android.util.Log;
import com.lottery.im.api.ApiClient;
import com.lottery.im.api.observer.ShowTipObserver;
import com.lottery.im.api.result.ApiResult;
import com.lottery.im.api.result.entity.SignData;
import com.lottery.im.api.result.entity.integral.CommodityDetail;
import com.lottery.im.base.BaseFragmentPresenter;
import com.lottery.im.module.service.view.CommodityDetailView;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.TimeUnit;

/**
 * 作者：cyy
 * 时间：2018/9/18。
 */
public class CommodityDetailPresenter extends BaseFragmentPresenter<CommodityDetailView>{
  public CommodityDetailPresenter(Activity activity,
      CommodityDetailView iView,
      LifecycleProvider<FragmentEvent> provider) {
    super(activity, iView, provider);
  }

  public void queryCommodityDetail(int id){
    ApiClient.getApiRetrofitInstance()
        .queryCommodityDetail(id)
        .throttleFirst(2, TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .compose(provider.bindToLifecycle())
        .subscribe(new ShowTipObserver<CommodityDetail>(activity) {
          @Override public void onSuccess(CommodityDetail commodityDetail) {
            iView.loadCommodityDetailSuccess(commodityDetail);
          }
        });
  }
}
